package com.qipay.baas.mapper;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.qipay.baas.model.CpAccount;

public class CpAccountSqlProvider {

    public String insertSelective(CpAccount record) {
        BEGIN();
        INSERT_INTO("cp_account");
        
        if (record.getCpId() != null) {
            VALUES("cp_id", "#{cpId,jdbcType=BIGINT}");
        }
        
        if (record.getBalance() != null) {
            VALUES("balance", "#{balance,jdbcType=BIGINT}");
        }
        
        if (record.getBalanceAvailable() != null) {
            VALUES("balance_available", "#{balanceAvailable,jdbcType=BIGINT}");
        }
        
        if (record.getBalanceAdvance() != null) {
            VALUES("balance_advance", "#{balanceAdvance,jdbcType=BIGINT}");
        }
        
        if (record.getBalanceDisabled() != null) {
            VALUES("balance_disabled", "#{balanceDisabled,jdbcType=BIGINT}");
        }
        
        if (record.getBalanceAdvanceWidthdraw() != null) {
            VALUES("balance_advance_widthdraw", "#{balanceAdvanceWidthdraw,jdbcType=BIGINT}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(CpAccount record) {
        BEGIN();
        UPDATE("cp_account");
        
        if (record.getBalance() != null) {
            SET("balance = #{balance,jdbcType=BIGINT}");
        }
        
        if (record.getBalanceAvailable() != null) {
            SET("balance_available = #{balanceAvailable,jdbcType=BIGINT}");
        }
        
        if (record.getBalanceAdvance() != null) {
            SET("balance_advance = #{balanceAdvance,jdbcType=BIGINT}");
        }
        
        if (record.getBalanceDisabled() != null) {
            SET("balance_disabled = #{balanceDisabled,jdbcType=BIGINT}");
        }
        
        if (record.getBalanceAdvanceWidthdraw() != null) {
            SET("balance_advance_widthdraw = #{balanceAdvanceWidthdraw,jdbcType=BIGINT}");
        }
        
        WHERE("cp_id = #{cpId,jdbcType=BIGINT}");
        
        return SQL();
    }
}